/*Set-Up*/
#delimit;
clear;
set more off;
cd "C:\data\PowerSharing";
log using MaleskyCammet_Replication, replace;
pause on;


/*************************************************************************************************************************/ 
/*Using New Data*/
#delimit;
use CammetMalesky_APSA_powersharing_v3_R&R.dta;

label variable peacedur "Duration of Peace in Months";
label variable peacedur_parentheses "Duration of Peace in Months Original";
label variable peacefail "Peace Failure =1";  

/*CORRECTIONS*/
replace peacefail=0 if idnumber==51;
replace thrdpart=0 if idnumber==41;
replace thrdpart=0 if idnumber==42;
replace ldeadper=ln(deadper+1);
drop if idnumber==.;


replace wdi_lifexp2 =61 if idnumber==49;
replace  coalitioninlegislature=0 if idnumber==52;
replace  politicalps=0 if idnumber==52;

pause; 

/*Cannot Run Model if Peace Duration==0*/
replace peacedur=.1 if peacedur==0;

/*Zimbabwe falls apart in 2008*/
replace peacefail=1 if idnumber==35;

/*Missing Checks Data*/
replace dpi_checks1=0 if dpi_checks1==.;
replace dpi_checks2=0 if dpi_checks2==.;
replace dpi_system1=3 if dpi_system1==.;
replace dpi_system2=3 if dpi_system2==.;
replace  peacedur_parentheses=120 if  idnumber2==39;
replace  peacedur_parentheses=72 if  idnumber2==51;


/*Set Data*/
order idnumber conflict region peacedur peacefail;
stset peacedur_parentheses, id(idnumber) failure(peacefail==1);
drop hh_org;
generate hh_org=1 if id<=38;
replace hh_org =0 if id>38;
pause;
label variable hh_org "Hartzell and Hodie Original Cases";


/*Creation of Mountainous Terrain Measure Following Fearon and Latin*/
generate ln_diff_elev=ln(( hi_elev- lo_elev)+1);
reg   mt_terrain  ln_diff_elev;
predict mt_terrain2;
replace mt_terrain=0 if ln_diff_elev<6.5;
replace mt_terrain=mt_terrain2 if mt_terrain==.;
generate ln_mt=ln(mt_terrain);
replace ln_mt=0 if ln_mt==.;


sort idnumber;
impute gled_pop region year  pop1 pop2 year, generate(gled_pop2);
impute gled_gdp region year   gdppcap1 gdppcap2 year, generate(gled_gdp2);


/*Label Variables*/
label variable idnumber "ID";
label variable conflict "Name of Conflict";

label variable politicalps "Political Power-Sharing HH Coding";

label variable coalitioninexecutive "Enforced Coalition in Executive";
label variable coalitioninlegislature "Enforced Coalition in Legislature";
label variable veto "Enforced Veto for Minority Groups";
label variable openpr "Open-List Proportional Representation";
label variable closedpr "Closed-List Proportional Representation";
label variable propadmin "Proportional Civil-Service Allotments";


label variable terrps "Territorial Power-Sharing HH Coding";
label variable militaryps "Military Power-Sharing HH Coding";
label variable econps "Economic Power-Sharing HH Coding";
label variable totalps "politicalps+terrps+militaryps+econps";

label variable prt "Previous Regime Type";
label variable durmonth "Duration of Conflict (months)";
label variable condurl "Duration of Conflict (months, log)";
label variable killthou "Thousands Killed";
label variable deadper "Dead Persons";
label variable ldeadper "Dead Persons (ln)";
label variable thrdpart "Third Party Enforcer";
label variable systruc "Cold War==1";
label variable conissue "Issue of Conflict";

label variable exp_gdp1 "Health expenditures/GDP Year 1";
label variable exp_gdp2 "Health expenditures/GDP Year 2";
label variable gengovexp_total1 "General government expenditure on health/total expenditure on health Year 1";
label variable gengovexp_total2 "General government expenditure on health/total expenditure on health Year 2";
label variable gengovexp_totalgov1 "General government expenditure on health /total government expenditure Year 1";
label variable gengovexp_totalgov2 "General government expenditure on health /total government expenditure Year 2";
label variable pocketexp_privatexp1 "Out-of-pocket expenditure on health/private expenditure on health Year 1";
label variable pocketexp_privatexp2 "Out-of-pocket expenditure on health/private expenditure on health Year 2";
label variable wdi_lifexp1 "Life expectancy Year 1";
label variable wdi_lifexp2 "Life expectancy Year 2";
label variable wdi_mort1 "Infant mortality Year 1";
label variable wdi_mort2 "Infant mortality Year 2";
label variable ds_gini "Gini";
label variable utip_ehii "Estimated household income inequality";


label variable wbgi_vae "Voice and Accountability Estimate around the time of peace agreement";
label variable wbgi_vae5 "Voice and Accountability Estimate 5 years or more after peace agreement";
label variable wbgi_pse "Political Stability estimate at time of peace agreement";
label variable wbgi_pse5 "Political Stability estimate 5 years or more after peace agreement";
label variable wbgi_gee "Government effectiveness estimate around the time of peace agreement";
label variable wbgi_gee5 "Government effectiveness estimate 5 years or more after peace agreement";
label variable wbgi_que "Regulatory quality estimate around the time of peace agreement";
label variable wbgi_que5 "regulatory quality estimate 5 years or more after peace agreement";
label variable wbgi_cce "Control of Corruption estimate around the time of peace agreement";
label variable wbgi_cce5 "Control of corruption estimate 5 years or more after peace agreement";
label variable bl_ayst15 "Average schooling years around the time of peace agreement";
label variable bl_ayst155 "Average schooling years 5 years or more after peace agreement";
label variable teduc_gdp "Total public education expenditures/GDP 5 years or more after peace agreement";

label variable sanit1 "Improved sanitation facilities (% of population with access) Year 1";
label variable sanit2 "Improved sanitation facilities (% of population with access) Year 2";
label variable water1 "Improved water source (% of population with access) Year 1";
label variable water2 "Improved water source (% of population with access) Year 2";
label variable bribe1 "Informal payments to public officials (% of firms) Year 1";;
label variable bribe2 "Informal payments to public officials (% of firms) Year 2";
label variable litrate1 "Literacy rate, adult total (% of people ages 15 and above) Year 1";
label variable litrate2 "Literacy rate, adult total (% of people ages 15 and above) Year 2";
label variable milexp1 "Military expenditure (% of central government expenditure) Year 1";
label variable milexp2 "Military expenditure (% of central government expenditure) Year 2";
label variable rdspaved1 "Roads, paved (% of total roads) Year 1";
label variable rdspaved2 "Roads, paved (% of total roads) Year 2";
label variable rdstotal1 "Roads, total network (km) Year 1";
label variable rdstotal2 "Roads, total network (km) Year 2";
label variable taxrev1 "Tax revenue (% of GDP) Year 1";
label variable taxrev2 "Tax revenue (% of GDP) Year 2";
label variable directtax1 "Taxes on income, profits and capital gains (% of total taxes) Year 1";
label variable directtax2 "Taxes on income, profits and capital gains (% of total taxes) Year 2";
label variable elecout1 "Value lost due to electrical outages (% of sales) Year 1";
label variable elecout2 "Value lost due to electrical outages (% of sales) Year 2";
label variable pwrcons1 "Electric power consumption (kWh per capita) Year 1";

label variable pop1 "Total population Year 1";
label variable pop2 "Total population Year 2";
label variable gdppcap1 "GDP per capita (constant 2000 US$) Year 1";
label variable gdppcap2 "GDP per capita (constant 2000 US$) Year 2";

generate ln_pop1=ln( pop1+1);
generate ln_pop2=ln( pop2+1);
generate ln_gdppcap1=ln( gdppcap1+1);
generate ln_gdppcap2=ln( gdppcap2+1);


label variable dpi_checks1 "Checks - Year after Conflict";
label variable dpi_checks2 "Checks - 5 Years after Conflict";
label variable dpi_system1 "System - Year after Conflict";
label variable dpi_system2 "System - 5 Years after Conflict";
generate ln_pwrcons =ln(pwrcons2+1);
replace veto=0 if  idnumber2==53;
generate region5=1 if region==5;
replace region5=0 if region !=5;
replace year_end=2000 if year_end==2;
generate ln_gledgdp=ln(gled_gdp);
generate ln_gledpop=ln(gled_pop);
pause;

/**************************************************Table 1: DESCRIPTIVES************************************************************/
generate politicalps_oth=1 if politicalps==1 &  coalitioninexecutive==0 &  coalitioninlegislature==0 &  veto==0  & propadmin==0 &  openpr==0 &  closedpr==0;
replace politicalps_oth=0 if politicalps_oth==. & politicalps !=.;

#delimit
foreach x in  politicalps coalitioninexecutive coalitioninlegislature veto openpr closedpr propadmin politicalps_oth terrps militaryps econps{;
tab `x';
tabstat  peacefail   if `x' ==1, statistics(mean);
tabstat  peacedur  if `x' ==1, statistics(mean);
};



count if totalps==1 & politicalps==1;
count if totalps==1 &  terrps==1;
count if totalps==1 &   militaryps==1;
count if totalps==1 &    econps==1;

generate total_political_ps= coalitioninexecutive + coalitioninlegislature + veto + openpr + closedpr + propadmin;
replace total_political=0 if  idnumber2==53;

tab totalps;
tab total_political;
sum totalps total_political;




/**************************************************************************************************************************/



pwcorr  politicalps coalitioninexecutive coalitioninlegislature veto openpr closedpr, star(5);

/*Generate Aggregate Power-Sharing Measures*/
generate enforced_coalition = 0 if  coalitioninexecutive==0 &  coalitioninlegislature==0;
replace enforced_coalition = 1 if  coalitioninexecutive==1 |  coalitioninlegislature==1;
tab enforced_coalition;
generate proportional_rep=1 if  openpr==1| closedpr==1;
replace proportional_rep=0 if  openpr==0 &  closedpr==0;
tab enforced_coalition proportional_rep;
pause;


/*REVISE AND RESUMBIT ANALYSIS**********************************************************************************************************/

/*TABLE 2: Differential Effect of Power Sharing*/
generate totalps2= totalps- politicalps;

#delimit;
/*Model 1*/
streg totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform replace;
/*Model 2*/
streg politicalps  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 3*/
streg closedpr totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 4*/
streg openpr totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 5*/
streg coalitioninexecutive totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 6*/
streg coalitioninlegislature totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 7*/
streg propadmin totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform;
/*Model 8*/
streg veto totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_type,  bdec(3) tdec(3) e(all) eform excel;



/*DESCRIPTIVES***********************************/


/*Web Appendix 1*/
sum closedpr openpr  coalitioninexecutive coalitioninlegislature veto propadmin  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict ln_gledgdp ln_gledpop;
pause;

/*Web Appendix 2*/
pwcorr closedpr openpr  coalitioninexecutive coalitioninlegislature veto propadmin  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict ln_gledgdp ln_gledpop, star(5);
pause;




/*Sensitivity Analysis: WEB APPENDIX 3A*/
#delimit;
/*Model 1*/
streg closedpr, distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform replace;
/*Model 2*/
streg closedpr totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs;
outreg2 using jcr_rr_robust, bdec(3) tdec(3) e(all) eform;
/*Model 3*/
streg closedpr totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs if fractionalization !=. & strict !=., distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform;

/*Model 4*/
streg closedpr totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict, distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform;

/*Model 5*/
streg closedpr  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict if ln_gledgdp !=. &  ln_gledpop !=., distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform;

/*Model 6*/
streg closedpr  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict ln_gledgdp ln_gledpop, distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform;

/*Model 7*/
xi3: streg closedpr  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs i.region, distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) eform;

/*Model 8*/
streg closedpr openpr  coalitioninexecutive coalitioninlegislature veto propadmin  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict, distribution(weibull);
outreg2 using jcr_rr_robust,  bdec(3) tdec(3) e(all) excel;

/*F-Tests for Footnote in Web Appendix 3B*/
test closed=open;
test closed=  coalitioninexecutive;
test closed= coalitioninlegislature;
test closed=propadmin;
test closed=veto;
test open=  coalitioninexecutive;
test open= coalitioninlegislature;
test coalitioninexecutive= coalitioninlegislature;
pause;




/*FIGURE WEB APPENDIX 3b Based on Model 8 of Web Appendix 3A with new basline model*/

#delimit;
streg closedpr openpr  coalitioninexecutive coalitioninlegislature veto propadmin  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict, distribution(weibull);

stcurve,hazard range(0 150)
ytitle("Hazard Ratio") 
xtitle("") title("Baseline Hazard Ratio", size(medlarge)) ylab(0(.0013).0026, labsize(vsmall));


graph save hazard_base.gph, replace;

stcurve, hazard at1(closedpr=1  openpr=0  coalitioninexecutive=0  coalitioninlegislature=0  veto=0  propadmin=0)  
at2(closedpr=0  openpr=1  coalitioninexecutive=0  coalitioninlegislature=0  veto=0  propadmin=0)   
at5(closedpr=0  openpr=0  coalitioninexecutive=0  coalitioninlegislature=0  veto=1  propadmin=0) range(0 150)
ytitle("Hazard Ratio")  legend(rows(1) size(small) label(1 Closed-List PR)  label(2 Open-List PR) label(3 Minority Veto)  position(12) )
title("") xtitle("") ylab(0(.0004).0008, labsize(vsmall));

graph save hazard_1.gph, replace;


stcurve, hazard at3(closedpr=0  openpr=0  coalitioninexecutive=1  coalitioninlegislature=0  veto=0  propadmin=0)  
at4(closedpr=0  openpr=0  coalitioninexecutive=0  coalitioninlegislature=1  veto=0  propadmin=0)   at6(closedpr=0  
openpr=0  coalitioninexecutive=0  coalitioninlegislature=0  veto=0  propadmin=1) ytitle("Hazard Ratio")  range(0 150)
legend(rows(1) size(small) label(1 Executive Coalition) label (2 Legislative Coalition) label(3 Proportional Admin.) position(12) )
title("") xtitle("") ylab(0(.04).08, labsize(vsmall));

graph save hazard_2.gph, replace;

graph combine  hazard_2.gph hazard_base.gph hazard_1.gph, xcommon rows(3) title("Duration of Peace (Months)", size(large) margin(medsmall) position(6));
pause;




/**************************TABLE 3: SELECTION MODEL**************************************/
#delimit;
replace cl_region=100*cl_region;

/*Model 1: First Stage*/
xi3: probit closedpr  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs cl_region, robust;
mfx;
outreg2 using jcr_rr_twostage, mfx ctitle(mfx)   bdec(3) tdec(3) e(all)  replace;
predict iv_closed;
generate iv_closed2=1 if  iv_closed>.5;
replace iv_closed2=0 if iv_closed<=.5;

/*Model 2: Second Stage A*/
streg iv_closed totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform;

/*Model 3: Second Stage B*/
streg iv_closed2 totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs, distribution(weibull);
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform;



/*Model 4: First Stage*/
#delimit;
xi3: probit closedpr  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs strict fractionalization  ln_gledgdp ln_gledpop  cl_region, robust;
mfx;
outreg2 using jcr_rr_twostage, mfx ctitle(mfx)   bdec(3) tdec(3) e(all);
predict iv_closed3;
generate iv_closed4=1 if  iv_closed>.5;
replace iv_closed4=0 if iv_closed<=.5;

/*Model 5: Second Stage A*/
streg iv_closed3 totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs strict fractionalization  ln_gledgdp ln_gledpop, distribution(weibull);
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform;

/*Model 6: Second Stage B*/
streg iv_closed4 totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs strict fractionalization  ln_gledgdp ln_gledpop, distribution(weibull);
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform;

/*Robust to IV-2SLS and IV-2SLS Test Diagnostics on First Stage for Table*/
ivreg2 peacedur_parentheses  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs  (closedpr=cl_region), robust first;
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform;
ivreg2 peacedur_parentheses  totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs strict fractionalization  ln_gledgdp ln_gledpop  (closedpr=cl_region), robust first;
outreg2 using jcr_rr_twostage,  bdec(3) tdec(3) e(all) eform excel;
pause;


/*Figure 1. Predicted Use of Closed-List in Negotiated Settlement*/

#delimit;
twoway (fpfit iv_closed cl_region)
(scatter iv_closed cl_region if region==1, mlabsize(vsmall) mlabel(year) mlabposition(3) msymbol(diamond) mcolor(navy) mlabcolor(navy) msize(small))  
(scatter iv_closed cl_region if region==2, mlabel(year) mlabposition(3) msymbol(square) mlabsize(vsmall) mcolor(blue) mlabcolor(blue) msize(small))  
(scatter iv_closed cl_region if region==3, mlabel(year) mlabposition(3) msymbol(triangle) mlabsize(vsmall) mcolor(purple) mlabcolor(purple) msize(small))  
(scatter iv_closed cl_region if region==4, mlabel(year) mlabposition(3) msymbol(circle) mlabsize(vsmall) mcolor(maroon) mlabcolor(maroon) msize(small)) 
(scatter iv_closed cl_region if region==5, mlabel(year) mlabposition(3) msymbol(circle_hollow) mlabsize(vsmall) mcolor(green) mlabcolor(green) msize(small)) 
(scatter iv_closed cl_region if region==6, mlabel(year) mlabposition(3) msymbol(lgx) mlabsize(vsmall) mcolor(black) mlabcolor(black) msize(small))   
(scatter iv_closed cl_region if region==7, mlabel(year) mlabposition(3) msymbol(plus) mlabsize(vsmall) mcolor(gray) mlabcolor(gray) msize(small)),
legend( size(vsmall) rows(8) label(1 Smoothed Prediction) label(2 Africa) label(3 SE Asia) label(4 W Europe) label(5 E Europe/FSU) label(6 L. America) label(7 Middle East) label(8 S Asia)
ring(0) position(5))
xtitle("")
title("By Region and Settlement Year", size(vlarge))
ylabel(0(.1)1)
yline(0.5, lcolor(red) lpattern(shortdash) lwidth(medium));

graph save iv_region.gph, replace;


#delimit;
twoway (fpfit iv_closed cl_region)
(scatter iv_closed cl_region if closedpr==1, mlabsize(vsmall)  mlabposition(3) msymbol(diamond) mcolor(black) mlabcolor(black) msize(small))  
(scatter iv_closed cl_region if closedpr==0,  mlabposition(3) msymbol(square) mlabsize(vsmall) mcolor(maroon) mlabcolor(maroon) msize(small)),  
legend( size(vsmall) rows(8) label(1 Smoothed Prediction) label(2 Closed-List) label(3 Other) ring(0) position(5))
xtitle("")
title("By Actual Use of Closed-List", size(vlarge))
ylabel(0(.1)1)
yline(0.5, lcolor(red) lpattern(shortdash) lwidth(medium));

graph save iv_actual.gph, replace;

graph combine iv_region.gph iv_actual.gph, xcommon ycommon
title("Countries with Closed-List PR in Region during Settlement Year (%)", color(black) size(medium) margin(medsmall) position(6))
subtitle("Probability of Settlement w/Closed-List PR", size(medium) margin(medsmall) position(9) orientation(vertical));

graph save iv_combined, replace;
pause;



/*TABLE 4: Impact of Power-Sharing Institutions on Quality of Governance*/
generate settlement_age=2010- year_end;

#delimit;
set more off;
xi3: ivreg2 wbgi_gee5  cl_region thrd prt drugs ldead fractionalization ln_gledpop settlement_age  mt_terrain ln_gledpop, robust level(90);
outreg2 using jcr_rr_Gov,  bdec(3) tdec(3) e(all)  replace;
predict iv_closed5;
foreach x in wbgi_gee5 wbgi_que5 wbgi_cce5 ln_pwr litrate2 rdspaved2 exp_gdp2 milexp2 taxrev2 directtax2{;
xi3: ivreg2 `x' thrd prt drugs ldead fractionalization ln_gledpop settlement_age  mt_terrain ln_gledpop  ( closedpr=cl_region), robust level(90) first;
outreg2 using jcr_rr_Gov,  bdec(3) tdec(3) e(all);
};

reg wbgi_gee5 closedpr;
outreg2 using jcr_rr_Gov,  bdec(3) tdec(3) e(rmse) excel;


/*Robust with first stage*/
#delimit;
xi3: ivreg2 wbgi_gee5  wbgi_gee thrd prt drugs ldead  settlement_age  mt_terrain ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all)  replace;
xi3: ivreg2 wbgi_que5 wbgi_que thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 wbgi_cce5 wbgi_cce thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
generate ln_pwr1=ln(pwrcons1+1);
generate ln_pwr2=ln(pwrcons2+1);
generate ln_pwr3=ln(pwrcons3+1);
xi3: ivreg2 ln_pwr2 ln_pwr1 thrd prt drugs ldead   settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 litrate2 litrate1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 rdspaved2 litrate1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 exp_gdp2 exp_gdp1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 milexp2 milexp1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 taxrev2 taxrev1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 directtax2 directtax1 thrd prt drugs ldead  settlement_age  mt_terrain  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);

/*No Controls*/
xi3: ivreg2 wbgi_gee5  wbgi_gee  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all) ;
xi3: ivreg2 wbgi_que5 wbgi_que  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 wbgi_cce5 wbgi_cce   ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 ln_pwr2 ln_pwr1 ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 litrate2 litrate1  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 rdspaved2 rdspaved1  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 exp_gdp2 exp_gdp1  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 milexp2 milexp1  ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 taxrev2 taxrev1   ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all);
xi3: ivreg2 directtax2 directtax1   ( closedpr=cl_region), robust level(90);
outreg2 using jcr_rr_GovSens,  bdec(3) tdec(3) e(all) excel;



/*TABLE 5: Table 5: Impact of Closed-List PR after Government Controls*/
#delimit;
set more off;
streg iv_closed4 totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict   if wbgi_gee5 !=., distribution(weibull) level(90) ;
outreg2 using jcr_rr_GovSurvival,  bdec(3) tdec(3) e(all) eform ci replace;

#delimit;
foreach x in wbgi_gee5 wbgi_que5 wbgi_cce5  litrate2 exp_gdp2 directtax2 {;
streg totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict `x', distribution(weibull) level(90);
outreg2 using jcr_rr_GovSurvival,  bdec(3) tdec(3) eform e(all) ci;
streg iv_closed4 totalps2 prt thrdp  ldeadper ethnicwar mt_terrain drugs fractionalization strict `x' , distribution(weibull) level(90) ;
outreg2 using jcr_rr_GovSurvival,  bdec(3) tdec(3) eform e(all) ci;
test iv_closed4 `x';
};

reg wbgi_gee5 closedpr;
outreg2 using jcr_rr_GovSurvival,  bdec(3) tdec(3) e(rmse) eform excel;




/***********************WEB APPENDIX 6A and 6B: CASE SELECTION**************************************************/

factor ln_pwrcons litrate2 milexp2 exp_gdp2 taxrev2 directtax2, pcf;
rotate, varimax;
predict public_goods revenue;
pwcorr public_goods revenue  wbgi_gee5  ln_pwrcons, star(10);




sum wbgi_gee5 ln_pwrcons;

/*WEB APPENDIX 6B*/

#delimit;
twoway (scatter wbgi_gee5 ln_pwrcons if  closedpr==1, mlabel(conflict) mlabsize(tiny) msymbol(diamond) 
mcolor(blue) msize(vsmall)) (scatter wbgi_gee5 ln_pwrcons if  closedpr==0, mlabel(conflict) mlabsize(tiny)
 msymbol(square) mcolor(red) msize(vsmall)), ytitle("WB: Gov't Effectiveness After 5 Years") 
xtitle("Power Consumption, ln(kw/cap)")   yline(-.73, lpattern(dash))  xline(5.81,lpattern(dash))
legend(rows(2) size(vsmall) label (1 Closed Proportional Rep) 
label (2 Other Power-Sharing) position(5) ring(0)) 
note("Dashed Lines Represent Mean Values of Variables", size(vsmall));

graph save case_select2.gph, replace;


/*WEB APPENDIX 6A*/

#delimit;
twoway (scatter wbgi_gee5  peacedur_parentheses if  closedpr==1, mlabel(conflict) mlabsize(tiny) msymbol(diamond) mcolor(blue) 
msize(vsmall)) (scatter wbgi_gee5  peacedur_parentheses if  closedpr==0, mlabel(conflict) mlabsize(tiny) msymbol(diamond) 
mcolor(green) msize(vsmall)), ytitle("WB: Gov't Effectiveness After 5 Years") xtitle("Duration of Peace (months)")  
yline(-.73, lpattern(dash))  xline(125.796 ,lpattern(dash)) legend(rows(4) size(vsmall) label (1 Closed Proportional Rep) 
label (2 Other Power-Sharing) label (3 Mean WB Governance) label (4 Mean Peace Duration) position(5) ring(0)) 
note("Dashed Lines Represent Mean Values of Variables", size(vsmall));

graph save case_select1.gph, replace;


save CammetMalesky_APSA_powersharing_v2.dta, replace;



/**********************************FIGURE 2:  MARGINAL GOVERNANCE EFFECTS*****************************************************/
#delimit;
use "C:\data\PowerSharing\governance3.dta", clear;

label define type 1 "Closed-List (Baseline)" 2 "Effectiveness" 3 "Regulation" 4 "Corruption Control" 5 "Literacy" 6 "Health/GDP" 7 "Income Tax", replace;



twoway (rcap low high  governance2 if control==0, sort lcolor(navy) mcolor(navy)  
horizontal msize(medlarge) lwidth(medthick) lcolor(navy)), 
xline(1, lcolor(red) lwidth(medium) lpattern(dash)) ylab(1(1)7, valuelabel angle(horizontal)) ytitle("") 
xtitle("Hazard Ratio", size(medlarge) margin(medium)) xlab(0(.25)1.5) legend(rows(1) size(small) label(1 90% CI) 
ring(0) position(11)) title("Restricted", size(large));

graph save hazard_ci_restrict.gph, replace;

label define type 1 "Closed-List (Control)" 2 "Effectiveness" 3 "Regulation" 4 "Corruption Control" 5 "Literacy" 6 "Health/GDP" 7 "Income Tax", replace;

twoway (rcap low high  governance2 if control==1, sort lcolor(blue) mcolor(blue)  
horizontal msize(medlarge) lwidth(medthick) lcolor(blue) lpattern(blue)), xline(1, lcolor(red) lwidth(medium) lpattern(shortdash)) ylab(1(1)7, valuelabel angle(horizontal)) ytitle("") 
xtitle("Hazard Ratio", size(medlarge) margin(medium)) xlab(0(.25)1.5) legend(rows(2) size(small) label(1 90% CI) 
ring(0) position(11)) title("Controlling for Closed-List", size(large));


graph save hazard_ci_unrestricted.gph, replace;


graph combine hazard_ci_restrict.gph hazard_ci_unrestricted.gph, xcommon ycommon;

graph save hazard_ci_final.gph, replace;


log close;
